package com.jqb.jsplab.dao.proxy;

import com.jqb.jsplab.dao.IStudentDao;
import com.jqb.jsplab.dao.factory.DaoFactory;
import com.jqb.jsplab.dao.impl.StudentDaoImpl;
import com.jqb.jsplab.util.DBConnection;
import com.jqb.jsplab.vo.Student;

public class StudentDaoProxy implements IStudentDao {

	private StudentDaoImpl studentdaoimpl = null;
	private DBConnection dbc = null;

	public StudentDaoProxy() throws Exception {
		dbc = DaoFactory.getDBConnection();
		studentdaoimpl = new StudentDaoImpl(dbc.getConnection());
	}

	@Override
	public boolean isLogin(String name, String password) throws Exception {
		boolean flag = false;
		try {
			flag = studentdaoimpl.isLogin(name, password);
		} catch (Exception e) {
			throw e;
		} finally {
			dbc.close();
		}
		return flag;
	}

	@Override
	public Student findStudentById(int id) throws Exception {
		Student student = null;
		try {
			student = studentdaoimpl.findStudentById(id);
		} catch (Exception e) {
			throw e;
		} finally {
			dbc.close();
		}
		return student;
	}

	@Override
	public boolean isStudentExist(String name) throws Exception {
		boolean flag = false;
		try {
			flag = studentdaoimpl.isStudentExist(name);
		} catch (Exception e) {
			throw e;
		} finally {
			dbc.close();
		}
		return flag;
	}

	@Override
	public boolean createStudent(Student student) throws Exception {
		boolean flag = false;
		try {
			flag = studentdaoimpl.createStudent(student);
		} catch (Exception e) {
			throw e;
		} finally {
		}
		return flag;
	}

	@Override
	public int[] findStudentId() throws Exception {
		int[] id = null;
		try {
			id = studentdaoimpl.findStudentId();
		} catch (Exception e) {
			throw e;
		} finally {
		}
		
		return id;
	}

}
